package zdream.control.profile.mm;

import zdream.control.foe.mm.MegaMan;
import zdream.control.input.WorldInput;
import zdream.control.world.MFoe;
import zdream.control.profile.IProfile;
import zdream.control.world.LevelWorld;

import static zdream.control.world.MFoeConstants.*;

/**
 * @author Zdream
 * @date 2023-12-27
 * @since 0.0.1
 */
public class MegaManProfile implements IProfile {
	public MegaMan foe;
	public int hp = 28 * HP_TOKEN, hpMax = 28 * HP_TOKEN;
	public WorldInput input;

	@Override
	public String getName() {
		return MegaMan.NAME;
	}

	@Override
	public MFoe createFoe(LevelWorld world) {
		return foe = new MegaMan(world);
	}

	@Override
	public int getHp() {
		return foe == null ? hp : (hp = foe.healthModule.hp);
	}

	@Override
	public int getHpMax() {
		return foe == null ? hpMax : (hpMax = foe.healthModule.hpMax);
	}

	@Override
	public void setHp(int hp) {
		if (foe != null) {
			foe.healthModule.hp = hp;
		}
		this.hp = hp;
	}

	@Override
	public void setHpMax(int hpMax) {
		if (foe != null) {
			foe.healthModule.hpMax = hpMax;
		}
		this.hpMax = hpMax;
	}

	@Override
	public boolean alive() {
		return foe != null && !foe.isDestroyed();
	}

	@Override
	public void reset() {
		this.foe = null;
		this.hp = hpMax;
	}

	@Override
	public void refresh() {
		if (foe == null) {
			return;
		}
		hp = foe.healthModule.hp;
		hpMax = foe.healthModule.hpMax;
	}

	@Override
	public void setInput(WorldInput input) {
		this.input = input;
		if (this.foe != null) {
			foe.putInput(input);
		}
	}

	@Override
	public WorldInput getInput() {
		return input;
	}
}
